limsMaterial.expirePage = {

    create: function () {
        var _this = this;
        Gikam.create('layout', {
            north: {
                height: '60%',
                items: [_this.getBaseInfoTabParam()]
            },
            center: {
                items: [_this.getStandardInventoryTabParam()]
            },
            renderTo: workspace.window.$dom
        });
    },

    getBaseInfoTabParam: function () {
        var _this = this;
        return {
            type: 'grid',
            id: _this.idManager.materialGrid,
            url: limsMaterial.baseUrl + '/queries',
            columns: limsMaterial.getShowListColumns(),
            requestData: {
                expire_raw: '1'
            },
            page: true,
            service: 'limsMaterialServiceImpl',
            onRowActive: function (index, row) {
                _this.refreshTabs(row)
            },
            onLoadSuccess: function (rows) {
                if (!Gikam.isEmpty(rows)) {
                    this.activeRowByIndex(0)
                } else {
                    _this.refreshTabs(null)
                }
            },
            deleteFormatter: function (row) {
                return row.matName || row.id
            }
        }
    },

    refreshTabs: function (row) {
        let _this = this
        Gikam.getAsyncComp(_this.idManager.inventoryGrid).done(grid => {
            if (row && row.id) {
                grid.refresh({
                    url: _this.urlManager.inventoryGrid + '/queries',
                    requestData: {
                        matCode_EQ: row.matCode
                    }
                })
            } else {
                grid.refresh({
                    url: _this.urlManager.inventoryGrid + '/queries',
                    requestData: {
                        matCode_EQ: -1
                    }
                })
            }
        })
    },

    getStandardInventoryTabParam: function () {
        var _this = this;
        return {
            type: 'tab',
            id: 'standard-inventory-expire--grid-tab',
            fill: true,
            panels: [{
                title: 'T_LIMS_STANDARD_INVENTORY.SERVICE_NAME',
                items: [{
                    type: 'grid',
                    id: _this.idManager.inventoryGrid,
                    columns: limsMaterial.getStandardInventoryEditListColumns(),
                    readonly: true,
                    service: 'limsStandardInventoryServiceImpl',
                }]
            }]
        }
    },

    idManager: {
        materialGrid: 'lsi-material-expire-list-grid',
        inventoryGrid: 'lsi-standard-inventory-expire--list-grid',
    },

    urlManager: {
        materialGrid: limsMaterial.baseUrl,
        inventoryGrid: IFM_CONTEXT + '/secure/basemodule/rm/standard-inventorys',
    },

    init: function () {
        this.param = {};
        this.create();
    }
};
